import QtQuick 2.12
import QtQuick.Controls 2.12
import QtQuick.Layouts 1.12
import ConfigElementType 1.0
import "qrc:/qmlComponents/ConfigManager"
import "qrc:/qmlComponents/AxisModulePos"
import "qrc:/qmlComponents/VisionViewer"
import "qrc:/qmlComponents/CustomizedUIElement"

Item {
    RowLayout{
        spacing: 40

        ColumnLayout{
            Layout.alignment: Qt.AlignTop

            ConfigRow{
                enabled: false
                configModel: bhConfig
                configName: "bhToSTCameraOffsetX"
                Component.onCompleted: {
                    init(ConfigElementType.Double)
                }
            }
            ConfigRow{
                enabled: false
                configModel: bhConfig
                configName: "bhToSTCameraOffsetY"
                Component.onCompleted: {
                    init(ConfigElementType.Double)
                }
            }
            Button{
                text: qsTr("CalibrateBHToSTCameraOffset")
                onClicked: {
                    tem.runSingleCmd(bonderHead, "calibrateBHToSTCameraOffset")
                }
            }
            Button{
                text: qsTr("MoveToPickSTCaliGlass")
                onClicked: {
                    tem.runSingleCmd(bonderHead, "moveToPickSTCaliGlass")
                }
            }

            ObjectEditor{
                sectionName: "stCameraToUplookCameraOffset"
                configModel: stCameraToUplookCameraOffset
                Component.onCompleted: {
                    init(true)
                }
            }
            Button{
                text: qsTr("CalibrateSTCameraToUplookCameraOffset")
                onClicked: {
                    tem.runSingleCmd(bonderHead, "calibrateSTCameraToUplookCameraOffset")
                }
            }
            Button{
                text: qsTr("PlaceCaliGlassToSTCameraCenter")
                onClicked: {
                    tem.runSingleCmd(bonderHead, "placeCaliGlassToSTCameraCenter")
                }
            }
        }

        ColumnLayout{
            Layout.alignment: Qt.AlignTop

            ArrayEditor{
                sectionName: "stCameraToUplookCameraOffsetOfEachRow"
                configModel: stCameraToUplookCameraOffsetOfEachRow
                arrayItemAddRemovable: false
                listMaxHeight: 300
                Component.onCompleted: {
                    init()
                }
            }
            Button{
                text: qsTr("ResetSTCameraToUplookCameraOffsetOfEachRow")
                onClicked: {
                    bonderHead.resetSTCameraToUplookCameraOffsetOfEachRow()
                }
            }

            Button{
                text: qsTr("CalibrateSTCameraToUplookCameraOffsetOfEachRow")
                onClicked: {
                    tem.runSingleCmd(bonderHead, "calibrateSTCameraToUplookCameraOffsetOfEachRow")
                }
            }
        }

        GroupBox{
            Layout.alignment: Qt.AlignTop
            ColumnLayout{
                RowLayout{
                    Label{
                        text: qsTr("MaxRandomXYOffsetForPick_mm")
                    }
                    TextField{
                        id: maxRandomXYOffsetForPick
                        text: "0"
                        implicitWidth: 80
                        selectByMouse: true
                        validator: DoubleValidator{
                            notation: DoubleValidator.StandardNotation
                        }
                    }
                }
                RowLayout{
                    Label{
                        text: qsTr("MaxRandomRotationAfterPick_deg")
                    }
                    TextField{
                        id: maxRandomRotationAfterPick
                        text: "0"
                        selectByMouse: true
                        implicitWidth: 80
                        validator: DoubleValidator{
                            notation: DoubleValidator.StandardNotation
                        }
                    }
                }
                CheckBox{
                    id: chbUseCorrespondingCalibrationForEachRow
                    text: qsTr("UseCorrespondingCalibrationForEachRow")
                    checked: true
                }
                RowLayout{
                    Label{
                        text: qsTr("TargetMaxRandomXOffset_pixel")
                    }
                    TextField{
                        id: txtTargetXOffset
                        text: "0"
                        implicitWidth: 80
                        selectByMouse: true
                        validator: DoubleValidator{
                            notation: DoubleValidator.StandardNotation
                        }
                    }
                }
                RowLayout{
                    Label{
                        text: qsTr("TargetMaxRandomYOffset_pixel")
                    }
                    TextField{
                        id: txtTargetYOffset
                        text: "0"
                        implicitWidth: 80
                        selectByMouse: true
                        validator: DoubleValidator{
                            notation: DoubleValidator.StandardNotation
                        }
                    }
                }
                RowLayout{
                    Label{
                        text: qsTr("TargetMaxRandomThetaOffset_deg")
                    }
                    TextField{
                        id: txtTargetThetaOffset
                        text: "0"
                        implicitWidth: 80
                        selectByMouse: true
                        validator: DoubleValidator{
                            notation: DoubleValidator.StandardNotation
                        }
                    }
                }
                RowLayout{
                    Label{
                        text: qsTr("TestTimes:")
                    }
                    TextField{
                        id: txtTestTimes
                        text: "10"
                        implicitWidth: 80
                        selectByMouse: true
                        validator: IntValidator{}
                    }
                }

                RowLayout{
                    Button{
                        text: qsTr("TestBondOfEachRow")
                        onClicked: {
                            tem.runSingleCmd(bonderHead, "testBondOfEachRow", [maxRandomXYOffsetForPick.text,
                                             maxRandomRotationAfterPick.text, chbUseCorrespondingCalibrationForEachRow.checked,
                                             txtTargetXOffset.text, txtTargetYOffset.text, txtTargetThetaOffset.text, txtTestTimes.text])
                        }
                    }
                    Button{
                        text: qsTr("StopTest")
                        onClicked: {
                            tem.runSingleCmd(bonderHead, "stopTestBondOfEachRow")
                        }
                    }
                }
            }
        }
    }
}
